<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%@ taglib prefix="t" tagdir="/WEB-INF/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
		java.util.List<com.group4.DAO.ForumDAO> forums = com.group4.DB.Forum.getAllForum();
		session.setAttribute("forums", forums);
%>
<script>
	function submitForm(thisObj, thisEvent) {
		var topicTitle = $('#topicTitle').val();  
		var jsonDataObject = new Object();
		jsonDataObject.topicTitle = topicTitle;
		var jsonData = JSON.stringify(jsonDataObject);
		$.getJSON("exportservlet", {action:"export",json:jsonData}, function(data) {
			   alert(data.message);
			   $('#return_message').html(data.message);
			});
		return false;  // prevents the page from refreshing before JSON is read from server response
	}
</script>
<t:wrapper title="Forum Page">
	<div class="page-content">
		<div class="page-header">
			<h1>Topics</h1>
		</div>
		<div class="row">
			<div class="col-xs-6 widget-box transparent">
				<div class="widget-header widget-header-small">
					<h4>All Topics</h4>	
				</div>
				<div class="widget-body">
					<div class="widget-main padding-8">
						<c:forEach items="${forums}" var="forum" >
							<div class="profile-activity clearfix">
								<h6><a href="forum.jsp?id=${forum.ID}">${forum.forumHeadText}</a></h6>
							</div>
						</c:forEach>
							<div class="form-group">
								<label for="topic_title">New Topic Title</label>
								<input type="text" id="topicTitle" name="topic_title" class="form-control" placeholder="Title of your topic" required />
							</div>
							<div class="form-actions">
								<input class="btn" type="submit" name="submit" value="Add Topic" onclick="return submitForm(this, event);"> 
								
							</div>
					</div>		
				</div>
			</div>
		</div>
	</div>
</t:wrapper>